
from pathlib import Path
import random
import shutil

#目录初始化
shutil.rmtree('a',ignore_errors=True)
shutil.rmtree('dst',ignore_errors=True)
dir1 = Path('')
dir1_sub = Path('a/b/c/d/')
dir1_sub.mkdir(parents=True,exist_ok=True)

#随机生成四个字母的文件
for i in range(50):
    number_random = random.sample([i for i in range(97,123)],k=4)
    file_name = "".join([chr(i) for i in number_random])
    dir_name = random.sample(['a/','a/b/','a/b/c/','a/b/c/d/'],k=1)

    result_file = Path(*dir_name) / file_name
    result_file.touch()

#定义ignore函数
def ignore(src,names):
    p = Path(src)
    s1 = {i.name for i in p.rglob('[a-w]?*')}
    return s1
#复制
shutil.copytree('a','dst',ignore=ignore)


# 做得不错
